﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace UI.View.Repairs
{
    /// <summary>
    /// New.xaml 的交互逻辑
    /// </summary>
    public partial class New : Page
    {

        ViewModel.RepairViewModel vm;
        public New()
        {
            InitializeComponent();

            //生成单号

            vm = DataContext as ViewModel.RepairViewModel;

            vm.CurrRepair = new Model.R_Repair();

            vm.CurrRepair.Id = "WX" + DateTime.Now.ToString("yyyyMMddhhmmssfff");
        }

        private void btn_Cancle_Click(object sender, RoutedEventArgs e)
        {
            if (MainWindow.GetMain().Frm.CanGoBack)
            {
                MainWindow.GetMain().Frm.GoBack();

            }

        }

        private void btn_Save_Click(object sender, RoutedEventArgs e)
        {
            if(vm.CurrRepair!=null)
            {
                vm.CurrRepair.AppointmentTime = DateTime.Now;
                vm.CurrRepair.BuildId = cmb_SelectRoom.SelectRoom.BuildingId;
                vm.CurrRepair.RoomId = cmb_SelectRoom.SelectRoom.Id;
                vm.CurrRepair.RoomNo = cmb_SelectRoom.SelectRoom.No;
                vm.CurrRepair.State = "待维修";
                vm.Save(vm.CurrRepair);

                //保存完成后清空数据
                vm.CurrRepair = new Model.R_Repair();

                //返回主页
                MainWindow.GetMain().Frm.Navigate(new View.Repairs.List());
            }
        }
    }
}
